package site.lyweb.service.impl;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import site.lyweb.constant.Constant;
import site.lyweb.domain.dto.*;
import site.lyweb.domain.query.CourseScoreQuery;
import site.lyweb.domain.query.StudentCourseQuery;
import site.lyweb.mapper.CourseScoreMapper;
import site.lyweb.mapper.StudentCourseMapper;
import site.lyweb.service.CourseScoreService;
import site.lyweb.service.StudentCourseService;
import site.lyweb.utils.ExtBeanUtils;
import site.lyweb.utils.UUIDUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 深山老林
 * @description 针对表【student】的数据库操作Service实现
 * @createDate 2024-06-19 20:53:32
 */
@Service
public class CourseScoreServiceImpl implements CourseScoreService {
    @Resource
    private CourseScoreMapper courseScoreMapper;
    /**
     * 分页 + 搜索
     *
     * @param current
     * @param courseScoreQuery
     * @return
     */
    @Override
    public PageDTO<CourseScoreDTO> getCourseScoreByPage(Integer current, CourseScoreQuery courseScoreQuery) {
        //分页查询分两个查询，1、查符合条件的数据总条数；2、查询当前页的数据
        int totalRow = courseScoreMapper.selectByCount(courseScoreQuery);
        int start = (current - 1) * Constant.PAGE_SIZE;
        List<CourseScore> courseScoresList = courseScoreMapper.selectByPage(courseScoreQuery);
        int totalPage = totalRow / Constant.PAGE_SIZE;
        if (totalRow % Constant.PAGE_SIZE > 0) { //如果除不尽，总页数就需要加1
            totalPage ++;
        }
        //需要把 List<TUser> 转换为 List<UserInfoDTO>
        List<CourseScoreDTO> courseScoreDTOList = ExtBeanUtils.copyPropertiesForList(courseScoresList, CourseScoreDTO.class);

        return new PageDTO<>(current, Constant.PAGE_SIZE, totalRow, totalPage, courseScoreDTOList);

    }

    @Override
    public boolean updateCourseScore(String id,BigDecimal courseScore) {
        try{
            return courseScoreMapper.updateCourseScore(id,courseScore);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }


}




